//
//  ChosePayTypeView.m
//  IntegralWall
//
//  Created by 小焘无量 on 2022/10/5.
//

#import "ChosePayTypeView.h"

@interface ChosePayTypeView()

@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (nonatomic, copy) void (^chosePayTypeBlock)(NSString *payType);

@end

@implementation ChosePayTypeView

#pragma mark - LifeCycle
// 1 微信 2支付宝
+(void)showComplate:(void(^)(NSString *payType))chosePayTypeBlock {
    ChosePayTypeView *view = [[ChosePayTypeView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [kWindow addSubview:view];
    [view animationConfig];
    
    view.chosePayTypeBlock = ^(NSString *payType) {
        chosePayTypeBlock(payType);
    };
}

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
        self.frame = frame;
    }
    return self;
}

#pragma mark - view layout

#pragma mark - Event Response
// 微信
- (IBAction)weiChatPayAction:(id)sender {
    if(self.chosePayTypeBlock) {
        self.chosePayTypeBlock(@"1");
    }
    [self hidSelfWithAnimation];
}

// 支付宝
- (IBAction)aliPayAction:(id)sender {
    if(self.chosePayTypeBlock) {
        self.chosePayTypeBlock(@"2");
    }
    [self hidSelfWithAnimation];
}

// 取消
- (IBAction)cancelBtnAction:(id)sender {
    [self hidSelfWithAnimation];
}

#pragma mark - Delegate,DataSource

#pragma mark - Network

#pragma mark - Method
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches.allObjects lastObject];
    BOOL result = [touch.view isDescendantOfView:self.bgView];
    if (!result) {
        [self hidSelfWithAnimation];
    }
}

#pragma mark - Set Get

#pragma mark - Lazy

@end
